package com.anket;

import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
import javax.faces.event.PhaseListener;

import org.hibernate.SessionFactory;

import com.hibernate.util.HibernateUtil;

public class RenderResponsePhaseListener implements PhaseListener {

	
	public void afterPhase(PhaseEvent arg0) {
		
		
		SessionFactory sessionFactory = null;
		try {
			sessionFactory = HibernateUtil.getSessionFactory();
			sessionFactory.getCurrentSession().getTransaction().commit();
		} catch (Throwable ex) {
			System.err.println("Very unsuitable error occured ...");
			if (sessionFactory.getCurrentSession().getTransaction().isActive()) {
				sessionFactory.getCurrentSession().getTransaction().rollback();
			}
		}
	}

	
	public void beforePhase(PhaseEvent arg0) {
		

	}

	
	public PhaseId getPhaseId() {
		// TODO Auto-generated method stub
		return PhaseId.RENDER_RESPONSE;
	}

}
